package src.twice;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
import java.util.jar.JarFile;

public class TextFileConcatenation extends JFrame {

    File[] textFiles = null;

    protected void do_concatButton_actionPerformed(ActionEvent e){
        //省略校验代码
        BufferedReader reader = null;
        FileWriter writer = null;

        try {
            writer = new FileWriter("C:\\Users\\22528\\Desktop\\javaTest.txt");
            for (File textFile : textFiles){
                reader = new BufferedReader(new FileReader(textFile));
                String line;
                while ((line = reader.readLine()) != null){
                    writer.write(line);
                }
            }
            JOptionPane.showMessageDialog(this,"文件合并成功","提示信息",JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }finally {
            try {
                writer.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
            try {
                reader.close();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}
